﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX;

namespace MultiResolutioning.Structures
{
	/// <summary>
	/// Klasa reprezentuje trojkat siatki.
	/// </summary>
	public class Face
	{
		public int faceId;
		public Vertex[] vertices = new Vertex[3];
		public Vector3 normal;
		public bool removed = false;
		public object additionalField;

		/// <summary>
		/// Dokladna wersja funkcji normalizujacej wektory.
		/// </summary>
		/// <param name="vector">The vector.</param>
		private void CustomNormalization(ref Vector3 vector)
		{
			float length = vector.Length();
			vector.X = vector.X / length;
			vector.Y = vector.Y / length;
			vector.Z = vector.Z / length;
		}

		/// <summary>
		/// Oblicza wektor normalny do trojkata.
		/// </summary>
		public void ComputeNormal()
		{
			this.normal = Vector3.Cross(this.vertices[1].position - this.vertices[0].position,
																	this.vertices[2].position - this.vertices[1].position);

			if (this.normal.Length() == 0) return;
			//this.normal.Normalize();
			CustomNormalization(ref this.normal);
		}
	}
}
